<template>
  <div class="head">
    <div class="tit">
      <button class="tex1">异形件结算报表</button>
    </div>
    <div class="line" />
    <el-row>
      <el-col :span="24">
        <div class="title1">
          <el-form
            ref="form"
            style="
              display: flex;
              flex-wrap: wrap;
              margin-top: 24px;
              justify-content: space-between;
            "
            :model="form"
            label-width="80px"
          >
            <div
              style="
                display: flex;
                justify-content: space-between;
                flex-wrap: wrap;
                width: 1578px;
              "
            >
              <el-form-item class="text" label="日期">
                <el-date-picker
                  v-model="value"
                  type="daterange"
                  start-placeholder="开始日期"
                  end-placeholder="结束日期"
                  value-format="yyyy-MM-dd"
                  @change="changeTime"
                  style="width: 685px"
                />
              </el-form-item>
              <el-form-item class="text" label="业务类型">
                <el-select
                  @change="changeType"
                  v-model="value1"
                  class="input"
                  placeholder="请选择"
                  style="width: 286px"
                >
                  <el-option label="异形件" value="1" />
                  <el-option label="异形包" value="2" />
                </el-select>
              </el-form-item>
              <el-form-item class="text" label="日期维度">
                <el-select
                  v-model="form.timeType"
                  class="input"
                  placeholder="请选择"
                  style="width: 286px"
                >
                  <el-option label="按天" value="1" />
                  <el-option label="按时间段" value="2" />
                </el-select>
              </el-form-item>
            </div>
            <div>
              <el-form-item>
                <el-button type="primary" @click="onSubmit">查询</el-button>
                <el-button @click="khClear">重置</el-button>
              </el-form-item>
            </div>
          </el-form>
        </div>
        <div class="title1">
          <el-form
            ref="form"
            style="
              display: flex;
              justify-content: space-between;
              flex-wrap: wrap;
            "
            :model="form"
            label-width="80px"
          >
            <div
              style="
                display: flex;
                justify-content: space-between;
                flex-wrap: wrap;
                width: 764px;
              "
            >
              <!-- <el-form-item class="text" label="所属省份">
                                          <el-select v-model="mxForm.destinationProvince" class="input" placeholder="请选择目的省份" style="width: 286px;"
                                            @change="provinceChange">
                                            <el-option v-for="item in ProvinceList" :key="item.id" :label="item.province"
                                              :value="{ pid: item.pid, province: item.province }" />
                                          </el-select>
                                        </el-form-item> -->
              <!-- <el-form-item class="text" label="对象类型">
                                          <el-select placeholder="请选择" style="width: 286px;">
                                            <el-option v-for="item in cityList" :key="item.id" class="input" :label="item.city"
                                              :value="item.city" />
                                          </el-select>
                                        </el-form-item> -->
              <el-form-item class="text" label="对象名称">
                <el-select
                  :disabled="true"
                  placeholder="辽宁盘锦公司"
                  style="width: 286px"
                >
                  <el-option label="辽宁盘锦公司" value="1" />
                </el-select>
              </el-form-item>
            </div>
            <div>
              <el-form-item>
                <el-button @click="onSubmit"
                  ><i class="el-icon-upload2" />导出</el-button
                >
              </el-form-item>
            </div>
          </el-form>
        </div>
        <el-table
          :data="tableData"
          border
          max-height="734"
          :header-cell-style="{ background: '#f6f6f6' }"
          style="width: 100%"
        >
          <el-table-column
            type="index"
            width="50"
            :index="table_index"
            align="center"
          />
          <el-table-column
            prop="settleDate"
            label="结算日期"
            width="180"
            align="center"
          />
          <el-table-column
            prop="networkName.networkCode"
            label="结算对象编码"
            align="center"
          />
          <el-table-column
            prop="networkName.networkName"
            label="结算对象名称"
            align="center"
          />
          <el-table-column
            v-if="value1 === '2'"
            prop="packageNum"
            label="包数/元"
            align="center"
          />
          <el-table-column
            v-if="value1 === '2'"
            prop="ticketNum"
            label="票数/元"
            align="center"
          />
          <el-table-column
            v-if="value1 === '2'"
            prop="settleAmount"
            label="应付金额"
            align="center"
          />
          <el-table-column
            v-if="value1 === '1'"
            prop="receiptNum"
            label="应收件量"
            align="center"
          />
          <el-table-column
            v-if="value1 === '1'"
            prop="receiptAmount"
            label="应收金额"
            align="center"
          />
          <el-table-column
            v-if="value1 === '1'"
            prop="payNum"
            label="应付件量"
            align="center"
          />
          <el-table-column
            v-if="value1 === '1'"
            prop="payAmount"
            label="应付金额"
            align="center"
          />
        </el-table>
        <div
          style="
            display: flex;
            justify-content: space-between;
            margin-top: 51px;
          "
        >
          <div class="title2"></div>
          <div class="block" style="display: flex; justify-content: flex-end">
            <el-pagination
              background
              :current-page="current"
              :page-sizes="[10, 20, 30, 40]"
              :page-size="10"
              layout="total, prev, pager, next"
              :total="+total"
              prev-text="上一页"
              next-text="下一页"
              @size-change="handleSizeChange"
              @current-change="handleCurrentChange"
            />
          </div>
        </div>
      </el-col>
    </el-row>
  </div>
</template>

<script>
import { specialApedPartApi, specialApedPartApi1 } from "@/api/HqFinancePanel";
export default {
  components: {},
  data() {
    return {
      value1: "",
      value: "",
      form: {
        endTime: "",
        networkNameId: "1",
        pageDate: {
          pageNum: 1,
          pageSize: 10,
        },
        startTime: "",
        timeType: "",
      },
      tableData: [],
      current: "", // 页数
      pages: "", // 条数
      total: "", // 总数
    };
  },

  computed: {},

  created() {},

  methods: {
    // // 获取省
    // getProvince () {
    //   getProvinceList().then((res) => {
    //     if (res.code === 200) {
    //       this.ProvinceList = res.data
    //     }
    //   })
    // },
    // 序号
    table_index(index) {
      return (this.pages - 1) * this.current + index + 1;
    },
    // 选择时间
    changeTime() {
      this.form.startTime = this.value[0];
      this.form.endTime = this.value[1];
    },
    // 上一页
    handleSizeChange(val) {
      this.form.pageDate.pageSize = val;
      this.onSubmit();
    },
    // 下一页
    handleCurrentChange(val) {
      this.form.pageDate.pageNum = val;
      this.onSubmit();
    },
    changeType() {
      this.tableData = [];
    },
    table(res) {
      this.tableData = res.data.data;
      this.total = res.data.total;
      this.current = res.data.current;
      this.pages = res.data.pages;
    },
    // 查询
    async onSubmit() {
      console.log(123, this.value1);
      if (this.value1 === "1") {
        const res = await specialApedPartApi(this.form);
        this.table(res);
      } else if (this.value1 === "2") {
        const res = await specialApedPartApi1(this.form);
        this.table(res);
      }
    },
    // 重置
    khClear() {
      Object.keys(this.form).forEach((key) => {
        if (key !== "pageDate" && key !== "networkNameId") {
          this.form[key] = "";
        }
      });
      this.tableData = [];
      this.value = "";
      this.value1 = "";
      this.total = "";
      this.current = "";
      this.pages = "";
    },
  },
};
</script>
<style scoped lang="scss">
.tit {
  display: flex;

  .tex1 {
    margin-right: 48px;
    font-size: 16px;
    font-family: Source Han Sans CN;
    font-weight: 400;
    color: #666666;
    background: #fff;
    border: 1px #fff solid;
  }

  .active {
    font-family: Source Han Sans CN;
    font-weight: 700;
    color: #2087d0;
    position: relative;
  }

  .active::before {
    position: absolute;
    content: "";
    width: 110px;
    height: 2px;
    background: #2087d0;
    border-radius: 1px;
    bottom: -20px;
    left: 50%;
    transform: translate(-50%);
  }
}

.head {
  padding: 30px;
}

.title {
  font-size: 16px;
  font-family: Source Han Sans CN;
  font-weight: 400;
  color: #666666;
  margin-top: 20px;
}

.line {
  height: 1px;
  background: #d8d8d8;
  border-radius: 1px;
  margin-top: 19px;
}

.title1 {
  .text {
    font-size: 18px;
    font-family: Source Han Sans CN;
    font-weight: 400;
    color: #666666;

    .input {
      width: 286px;
      height: 36px;
      background: #ffffff;
      border-radius: 4px;
    }

    .input1 {
      width: 708px;
      height: 36px;
      background: #ffffff;
      border: 1px solid #b4b4b4;
      border-radius: 4px;
    }
  }
}

.title2 {
  font-size: 18px;
  font-family: Source Han Sans CN;
  font-weight: 400;
  color: #666666;
}
</style>
